<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
	:maskClosable="false"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">


      <a-form :form="form">
        <!--<a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="标题">
          <a-input placeholder="请输入标题" v-decorator="['title', {}]" />
        </a-form-item>-->
        <!--<input type="hidden" v-model="id" v-decorator="['id', {}]"/>
        <input type="hidden" v-model="taskId" />-->

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="审批意见">
          <!--<a-input placeholder="请输入原因" v-decorator="['reason', {}]" />-->
          <a-textarea placeholder="请输入审批意见" v-decorator="['comment', {}]"> </a-textarea>
        </a-form-item>

        <!--<a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="模型分类">
          <a-input placeholder="请输入模型分类" v-decorator="['category', {}]" />
        </a-form-item>-->
        <!--<a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="模型备注">
          <a-input placeholder="请输入备注" v-decorator="['description', {}]" />
        </a-form-item>-->

		
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
  import ATextarea from 'ant-design-vue/es/input/TextArea'

  export default {
    name: "ApplyModal",
    components: { ATextarea },
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        },
        url: {
          add: "/leave/task/complete",
          edit: "/model/model/edit",
        },
        id:"",
        taskId:"",
        flag:"",
        /*params:{
          flag:""
        }*/
      }
    },
    created () {
      this.url = "";
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record,flag) {
        // this.form.resetFields();
        // this.model = Object.assign({}, record);
         this.visible = true;
        // this.$nextTick(() => {
        //   this.form.setFieldsValue(pick(this.model,'rev','name','key','category','createTime','lastUpdateTime','version','metaInfo','deploymentId','editorSourceValueId','editorSourceExtraValueId','tenantId'))
		 //  //时间格式化
        // });
        this.id = record.id;
        this.taskId = record.id;
        this.flag = flag;

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = this.url.add;
            let method = 'post';
            /*if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }*/

            /*this.model.push({
              id:this.id,
              taskId:this.taskId
            });*/
            this.model.id = this.id;
            this.model.taskId = this.taskId;
            this.model.params = {
              flag:this.flag
            };
            //this.model.params.flag = this.flag;
            let formData = Object.assign(this.model, values);
            //时间格式化
            
            console.log(formData)
            httpAction("/handle/task/complete/"+this.taskId+"/"+this.flag+"/"+formData.comment,formData,method).then((res)=>{
              //console.log(res);
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>